import { Message, MessagePlugin } from 'tdesign-mobile-vue';
import { h } from 'vue';
import ChartMessage from '@/components/ChartMessage.vue';

const info = (content) => {
  MessagePlugin.closeAll();
  Message['info']({ offset: [10, 16], content, icon: true, duration: 2000 });
};

const success = (content) => {
  MessagePlugin.closeAll();
  Message['success']({ offset: [10, 16], content, icon: true, duration: 2000 });
};

const warning = (content) => {
  MessagePlugin.closeAll();
  Message['warning']({ offset: [10, 16], content, icon: true, duration: 2000 });
};

const error = (content) => {
  MessagePlugin.closeAll();
  Message['error']({ offset: [10, 16], content, icon: true, duration: 2000 });
};

const chart = (item = {}) => {
  MessagePlugin.closeAll();
  Message['info']({
    offset: [10, 16],
    icon: false,
    duration: -1,
    content: () => h(ChartMessage, { item })
  });
};

uni.$message = {
  info,
  success,
  warning,
  error,
  chart
};